<?php

namespace App\Controllers\City;

use App\Models\City\City;

class CityIsServe extends \App\Libs\Base\BaseAction
{

    public function execute()
    {
        if ($this->request->isPost()) {
            if (!$this->request->hasPost('cityName')) {
                return \App\Libs\Views\Json::view(1, '请指定城市名称！', null);
            }
            $ifServeCity = $this->request->getPost('cityName');
            $city = City::find([
                'conditions' => 'city_name like ?1 and is_show = 1',
                'bind' => [1 => '%' . $ifServeCity . '%']
            ]);
            if (!empty($city)) {
                return \App\Libs\Views\Json::view(0, '指定的城市在服务列表中', ['flag' => 0,'cityId'=>$city->id]);

            } else {
                return \App\Libs\Views\Json::view(1, '指定的城市不在服务列表中', ['flag' => 1]);
            }
        } else {
            return \App\Libs\Views\Json::view(1, '请求方式错误', null);

        }
    }
}
